package com.raos.validation.controller;

import com.raos.validation.model.SysRole;
import com.raos.validation.model.SysUser;
import com.raos.validation.response.R;
import com.raos.validation.util.ValidatorUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * 用户 控制器
 *  模拟校验的业务场景
 *
 * @author raos
 * @emil 991207823@qq.com
 * @date 2021/5/16 20:48
 */
@RestController
@RequestMapping("/user")
public class SysUserController {

    @PostMapping("/add")
    public R addUser(@RequestBody @Valid SysUser sysUser) {
        System.out.println("走到这里说明校验成功");
        System.out.println(sysUser);
        return R.ok(R.SUCCESS_MSG);
    }

    @PostMapping("/add2")
    public R addUser2(@RequestBody SysUser sysUser) {
        ValidatorUtils.validateEntity(sysUser);

        System.out.println("走到这里说明校验成功");
        System.out.println(sysUser);
        return R.ok(R.SUCCESS_MSG);
    }

    @PostMapping("/addRole")
    public R addRole(@RequestBody @Valid SysRole sysRole) {
        System.out.println("走到这里说明校验成功");
        System.out.println(sysRole);
        return R.ok(R.SUCCESS_MSG);
    }

}
